package com.ntt.benew.dictionary.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.blankj.utilcode.util.SizeUtils
import com.ntt.benew.dictionary.R
import com.ntt.benew.dictionary.entity.YDRelatedWords
import com.ntt.benew.dictionary.view.BorderedTextView

/**
 * Created by Android Studio.
 * User: tw
 * Date: 2023/11/3
 * Time: 17:33
 * 相关词 适配器
 */
class RelatedAdapter(val mContext: Context, val mData: List<YDRelatedWords>? = null) : RecyclerView.Adapter<RelatedAdapter.ViewHolder>() {
    class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {}

    override fun onCreateViewHolder(parent: ViewGroup, p1: Int): ViewHolder {
        val view =  LayoutInflater.from(mContext)
            .inflate(R.layout.item_word_cell, parent, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, p1: Int) {
        mData?.get(p1)?.let {
            val tvWord = holder.itemView.findViewById<BorderedTextView>(R.id.tv_word)
            tvWord.maxWidth = SizeUtils.dp2px(330f)
            tvWord.text = it.word
            val tvContent = holder.itemView.findViewById<TextView>(R.id.tv_content)
            tvContent.text = it.definition
        }
    }

    override fun getItemCount(): Int {
        return mData?.size ?: 0
    }
}